package com.xs.project.service.impl;

import com.xs.project.common.Result;
import com.xs.project.mapper.SysMsgMapper;
import com.xs.project.pojo.vo.SysLogReq;
import com.xs.project.pojo.vo.resp.OperateLogResp;
import com.xs.project.pojo.vo.resp.SysMsgResp;
import com.xs.project.service.SysMsgService;
import com.xs.project.utils.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class SysMsgServiceImpl implements SysMsgService {
    @Resource
    private SysMsgMapper sysMsgMapper;
    @Override
    public Result<Boolean> insertSysMsg(SysMsgResp request) {
        sysMsgMapper.insertSysMsg(request);
        return Result.success(true);
    }

    @Override
    public Result<Boolean> updateSysMsg(SysMsgResp request) {
        sysMsgMapper.updateSysMsg(request);
        return Result.success(true);
    }

    @Override
    public Result<Boolean> deleteSysMsg(Integer id) {
        sysMsgMapper.deleteSysMsg(id);
        return Result.success(true);
    }

    @Override
    public Result<List<SysMsgResp>> selectSysMsg(SysLogReq note) {

        List<SysMsgResp> list = sysMsgMapper.selectSysMsg(note.getNote());
        for (SysMsgResp resp : list) {
            resp.setCreateTimeStr(DateUtil.getDateStr(resp.getCreateTime()));
        }
        return Result.success(list);
    }

    @Override
    public Result<List<OperateLogResp>> selectOperateLog(String userId) {
        List<OperateLogResp> list = sysMsgMapper.selectOperateLog(userId);
        for (OperateLogResp resp : list) {
            resp.setCreateTimeStr(DateUtil.getDateStr(resp.getCreateTime()));
        }
        return Result.success(list);
    }
}
